#include <iostream>

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int x1, x2, y1, y2;

int main() {
    std::cin >> x1 >> y1 >> x2 >> y2;
    int delta_x = abs(x1 - x2);
    int delta_y = abs(y1 - y2);
    if (delta_x == 0 && delta_y == 0) std::cout << 0;
    else std::cout << gcd(delta_x, delta_y) - 1;
}